import request from './request'
import { AxiosPromise } from 'axios'

/**
 * 新增或修改返厂模块
 * @param {ReturnFactoryAPIRequest.ModuleForm} data - 返厂模块对象
 */
export const addOrUpdateReturnFactoryModule = (
  data: ReturnFactoryAPIRequest.ModuleForm,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/save',
    method: 'post',
    data,
  })
}

/**
 * 获取返厂地址库列表
 * @param {Object} data - 请求参数对象
 * @param {String} data.keyword - 联系人姓名/手机号
 * @param {Number} data.limit - 每页显示数量
 * @param {Number} data.page - 当前页码
 */
export const getReturnFactoryAddressList = (data: {
  keyword: string
  limit: number
  page: number
}): AxiosPromise<ReturnFactoryAPIResponse.AddressList> => {
  return request({
    url: '/repair/addr/store/getList',
    method: 'post',
    data,
  })
}

/**
 * 获取返厂模块列表
 * @param {Object} data - 获取返厂模块列表请求参数
 * @param {String} data.name - 搜索关键词
 * @param {Number} data.page - 当面页码
 * @param {Number} data.limit - 每页显示数量
 */
export const getReturnFactoryModuleList = (data: {
  limit: number
  page: number
  name: string
}): AxiosPromise<ReturnFactoryAPIResponse.ModulesList> => {
  return request({
    url: '/repair/module/getList',
    method: 'post',
    data,
  })
}

/**
 * 批量删除返厂模块
 * @param {Array<string>} ids - 返厂模块id集合
 */
export const modulesDel = (ids: Array<string>): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/delete',
    method: 'post',
    data: ids,
  })
}

/**
 * 模块批量启用/禁用
 * @param {Array<string>} ids - 返厂模块id集合
 * @param {Boolean} status - 状态：true-禁用，false-启用
 */
export const modulesUpdateStatus = (
  ids: Array<string>,
  status: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/updateStatus',
    method: 'post',
    params: {
      status,
    },
    data: ids,
  })
}

/**
 * 获取模块详情
 * @param {String} id - 模块id
 */
export const getModuleDetail = (
  id: string,
): AxiosPromise<ReturnFactoryAPIResponse.ModuleDetail> => {
  return request({
    url: `/repair/module/getDetail/${id}`,
    method: 'get',
  })
}

/**
 * 模块批量修改移动端的可见状态
 * @param {Array<string>} ids - 模块id集合
 * @param {Boolean} mobileShow - 可见状态：true-可见，false-不可见
 */
export const modulesUpdateMobileShow = (
  ids: Array<string>,
  mobileShow: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/updateMobileShow',
    method: 'post',
    data: ids,
    params: {
      mobileShow,
    },
  })
}

/**
 * 模块批量更改返厂审核方式
 * @param {Array<string>} ids 返厂模块ID集合
 * @param {1 | 2} repairCheckType - 返厂审核方式：1-按整单审核，2-单独审核
 */
export const modulesUpdateReturnFactoryCheckMethod = (
  ids: Array<string>,
  repairCheckType: 1 | 2,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/updateRepairCheckType',
    method: 'post',
    data: ids,
    params: {
      repairCheckType,
    },
  })
}

/**
 * 模块批量开启/关闭故障库
 * @param {Array<string>} ids - 返厂模块id集合
 * @param {Boolean} enabledFault - 是否开启故障库：false-关闭，true-开启
 */
export const modulesUpdateFaults = (
  ids: Array<string>,
  enabledFault: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/updateEnabledFault',
    method: 'post',
    data: ids,
    params: {
      enabledFault,
    },
  })
}

/**
 * 模块批量开启/关闭条码校验
 * @param {Array<string>} ids - 模块id集合
 * @param {Boolean} enabledSnCodeCheck - 是否开启条码校对：true-开启、false-关闭
 */
export const modulesEnableSnCodeCheck = (
  ids: Array<string>,
  enabledSnCodeCheck: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/updateEnabledSnCodeCheck',
    method: 'post',
    data: ids,
    params: {
      enabledSnCodeCheck,
    },
  })
}

/**
 * 模块批量允许/禁止先发后收
 * @param {Array<string>} ids - 模块id集合
 * @param {Boolean} enabledFirstSendAfterIncom - 允许先发后收：true-开启、false-关闭
 */
export const modulesEnableSendBeforeIncome = (
  ids: Array<string>,
  enabledFirstSendAfterIncom: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/updateEnabledFirstSendAfterIncom',
    method: 'post',
    data: ids,
    params: {
      enabledFirstSendAfterIncom,
    },
  })
}

/**
 * 模块批量启用/关闭确认费用
 * @param {Array<string>} ids 模块id集合
 * @param {Boolean} sureFee - 确认费用：true-开启、false-关闭
 */
export const modulesEnableFeeConfirm = (
  ids: Array<string>,
  sureFee: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/updateSureFee',
    method: 'post',
    data: ids,
    params: {
      sureFee,
    },
  })
}

/**
 * 模块批量启用检测单流程
 * @param {Array<string>} ids - 模块id集合
 * @param {Boolean} enabledCheckProcess - 是否开启检测单流程：false-关闭，true-开启
 */
export const modulesEnableInspectProcess = (
  ids: Array<string>,
  enabledCheckProcess: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/updateEnabledCheckProcess',
    method: 'post',
    data: ids,
    params: {
      enabledCheckProcess,
    },
  })
}

/**
 * 模块批量启用服务报告
 * @param {Array<string>} ids - 模块id集合
 * @param {Boolean} enabledServiceReport - 是否启用服务报告：false-关闭，true-开启
 */
export const modulesEnableServiceReport = (
  ids: Array<string>,
  enabledServiceReport: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/updateEnabledServiceReport',
    method: 'post',
    data: ids,
    params: {
      enabledServiceReport,
    },
  })
}

/**
 * 新增/编辑自定义字段
 * @param {Object} data - 请求参数
 */
export const customFiledSave = (
  data: ReturnFactoryAPIRequest.CustomFileForm,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/field/save',
    method: 'post',
    data,
  })
}

/**
 * 获取自定义字段列表
 * @param {Object} data - 请求参数
 * @param {String} data.name - 搜索关键字
 * @param {Number} data.page - 当前页码
 * @param {Number} data.limit - 每页显示多少条
 */
export const getCustomFieldList = (data: {
  name: string
  limit: number
  page: number
}): AxiosPromise<ReturnFactoryAPIResponse.CustomFieldList> => {
  return request({
    url: '/repair/field/getList',
    method: 'post',
    data,
  })
}

/**
 * 获取返厂模块下拉选项
 * @param {Object} data - 请求参数
 * @param {String} data.name - 搜索关键词
 * @param {Number} data.limit - 每页显示数量
 * @param {Number} data.page - 当面页码
 */
export const getReturnFactoryModuleOptions = (data: {
  limit: number
  page: number
  name: string
}): AxiosPromise<ReturnFactoryAPIResponse.ModuleOptions> => {
  return request({
    url: '/repair/select/getRepairModule',
    method: 'post',
    data,
  })
}

/**
 * 获取自定义字段详情
 * @param {String} id - 字段id
 */
export const getReturnFactoryCustomFieldDetail = (
  id: string,
): AxiosPromise<ReturnFactoryAPIResponse.CustomFieldDetail> => {
  return request({
    url: `/repair/field/getDetail/${id}`,
    method: 'get',
  })
}

/**
 * 批量删除返厂自定义字段
 * @param {Array<string>} ids - 自定义字段id集合
 */
export const returnFactoryCustomFieldsDel = (ids: Array<string>): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/field/delete',
    method: 'post',
    data: ids,
  })
}

/**
 * 批量更新字段状态
 * @param {Array<string>} ids - 字段id集合
 * @param {Boolean} status - 字段状态：false-启用，true-禁用
 */
export const returnFactoryCustomFieldsUpdateStatus = (
  ids: Array<string>,
  status: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/field/updateFieldStatus',
    method: 'post',
    data: ids,
    params: {
      status,
    },
  })
}

/**
 * 字段批量更新移动端显示/隐藏
 * @param {Array<string>} ids - 返厂自定义字段id集合
 * @param {Boolean} mobileShow - 是否移动端显示：false-隐藏，true-显示
 */
export const returnFactoryCustomFieldsMobileShow = (
  ids: Array<string>,
  mobileShow: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/field/updateMobileShow',
    method: 'post',
    data: ids,
    params: {
      mobileShow,
    },
  })
}

/**
 * 字段批量必填/不必填
 * @param {String} ids - 字段id集合
 * @param {Boolean} required - 是否必填：false-不必填，true-必填
 */
export const returnFactoryCustomFieldsRequired = (
  ids: Array<string>,
  required: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/field/updateRequired',
    method: 'post',
    data: ids,
    params: {
      required,
    },
  })
}

/**
 * 新增或修改返厂检测字段
 * @param {Object} form - 请求参数
 */
export const returnFactoryInspectCustomFieldAddOrUpdate = (
  form: ReturnFactoryAPIRequest.InspectCustomField,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/check/field/save',
    method: 'post',
    data: form,
  })
}

/**
 * 获取返厂检测字段列表
 * @param {Object} data - 请求参数
 * @param {String} data.name - 搜索关键词
 * @param {Number} data.limit - 一页显示多少条
 * @param {Number} data.page - 当前页码
 */
export const getReturnFactoryInspectCustomField = (data: {
  page: number
  limit: number
  name: string
}): AxiosPromise<ReturnFactoryAPIResponse.InspectCustomFieldList> => {
  return request({
    url: '/repair/check/field/getList',
    method: 'post',
    data,
  })
}

/**
 * 获取返厂字段详情
 * @param {String} id - 字段id
 */
export const getReturnFactoryCustomFiledDetail = (
  id: string,
): AxiosPromise<ReturnFactoryAPIResponse.InspectCustomFieldDetail> => {
  return request({
    url: `/repair/check/field/getDetail/${id}`,
    method: 'get',
  })
}

/**
 * 批量删除返厂检测自定义字段
 * @param {Array<string>} ids - 字段id集合
 */
export const returnFactoryCustomFiledsDel = (ids: Array<string>): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/check/field/delete',
    method: 'post',
    data: ids,
  })
}

/**
 * 返厂检测报告自定义字段批量启用/禁用
 * @param {Array<string>} ids - 字段id集合
 * @param {Boolean} status - 字段状态：false-启用，true-禁用
 */
export const returnFactoryInspectCustomFieldsUpdateStatus = (
  ids: Array<string>,
  status: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/check/field/updateFieldStatus',
    method: 'post',
    data: ids,
    params: {
      status,
    },
  })
}

/**
 * 返厂检测报告自定义字段批量移动端显示/隐藏
 * @param {Array<string>} ids - 字段id集合
 * @param {Boolean} mobileShow - 是否移动端显示：false-隐藏，true-显示
 */
export const returnFactoryInspectCustomFIeldsMobileShow = (
  ids: Array<string>,
  mobileShow: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/check/field/updateMobileShow',
    method: 'post',
    data: ids,
    params: {
      mobileShow,
    },
  })
}

/**
 * 返厂检测报告自定义字段批量必填/不必填
 * @param {Array<string>} ids 字段id集合
 * @param {Boolean} required - 是否必填：false-不必填，true-必填
 */
export const returnFactoryInspectCustomFieldsRequired = (
  ids: Array<string>,
  required: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/check/field/updateRequired',
    method: 'post',
    data: ids,
    params: {
      required,
    },
  })
}

/**
 * 获取修改模块前的模块详情
 * @param {String} id - 模块id
 */
export const getReturnFactoryModuleDetailBeforeUpdate = (
  id: string,
): AxiosPromise<ReturnFactoryAPIResponse.ModuleDetailBeforeUpdate> => {
  return request({
    url: `/repair/module/getBeforeUpdateModule/${id}`,
    method: 'get',
  })
}

/**
 * 保存返厂模块关联返厂字段
 * @param {Object} data - 请求参数
 * @param {String} data.id - 返厂模块字段关联ID
 * @param {Boolean} data.mobileShow - 是否移动端显示:false-隐藏，true-显示
 * @param {String} data.repairFieldId - 返厂字段ID
 * @param {String} data.repairModuleId - 返厂模块ID
 * @param {Boolean} data.required - 是否必填：false-不必填，true-必填
 */
export const returnFactoryModuleConnectFieldSave = (
  data: ReturnFactoryAPIRequest.ModuleConnectFieldForm,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/field/save',
    method: 'post',
    data,
  })
}

/**
 * 批量删除模块关联字段
 * @param {Array<string>} ids - 模块关联字段id集合
 */
export const returnFactoryConnectFieldListDel = (ids: Array<string>): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/field/delete',
    method: 'post',
    data: ids,
  })
}

/**
 * 批量更改移动端显示
 * @param {Array<string>} ids - 模块关联字段id集合
 * @param {Boolean} mobileShow - 是否移动端显示:false-隐藏，true-显示
 */
export const returnFactoryConnectFieldListMobileShow = (
  ids: Array<string>,
  mobileShow: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/field/updateMobileShow',
    method: 'post',
    data: ids,
    params: { mobileShow },
  })
}

/**
 * 批量更改必填字段
 * @param {Array<string>} ids - 模块关联字段id集合
 * @param {Boolean} required - 是否必填：false-不必填，true-必填
 */
export const returnFactoryConnectFieldListRequired = (
  ids: Array<string>,
  required: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/field/updateRequired',
    method: 'post',
    data: ids,
    params: { required },
  })
}

/**
 * 获取返厂自定义字段选项
 * @param {Object} data - 请求参数
 * @param {String} data.name - 搜索关键词
 * @param {Number} data.limit  - 每页显示数量
 * @param {Number} data.page - 当面页码
 */
export const getReturnFactoryCustomFieldOptions = (data: {
  limit: number
  page: number
  name: string
}): AxiosPromise<ReturnFactoryAPIResponse.CustomFieldOptions> => {
  return request({
    url: '/repair/select/getRepairFieldSelect',
    method: 'post',
    data,
  })
}

/**
 * 获取返厂模块关联字段列表
 * @param {String} moduleId - 模块id
 * @param {Object} data - 请求参数
 * @param {Number} data.limit - 一页显示多少条
 * @param {Number} data.page - 当前页码
 */
export const getReturnFactoryModuleConnectFieldList = (
  moduleId: string,
  data: { limit: number; page: number },
): AxiosPromise<ReturnFactoryAPIResponse.ModuleCustomFieldConnectList> => {
  return request({
    url: `/repair/module/field/getList/${moduleId}`,
    method: 'post',
    data,
  })
}

/**
 * 根据返厂模块关联字段ID获取详情
 * @param {String} fieldId - 关联字段id
 */
export const getReturnFactoryModuleCustomFieldConnectDetail = (
  fieldId: string,
): AxiosPromise<ReturnFactoryAPIResponse.CustomFieldConnectDetail> => {
  return request({
    url: `/repair/module/field/getDetail/${fieldId}`,
    method: 'get',
  })
}

/**
 * 新建返厂
 * @param data - 请求参数
 */
export const returnFactoryCreate = (
  data: ReturnFactoryAPIRequest.Create,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/save',
    method: 'post',
    data,
  })
}

/**
 * 获取新建时的自定义字段
 * @param {String} id - 模块id
 */
export const getReturnFactoryModuleCustomFieldById = (
  id: string,
): AxiosPromise<ReturnFactoryAPIResponse.CustomFiledForCreate> => {
  return request({
    url: `/repair/select/getRepairModuleField/${id}`,
    method: 'get',
  })
}

/**
 * 获取返厂列表
 * @param data - 请求参数
 */
export const getReturnFactoryList = (
  data: ReturnFactoryAPIRequest.GetList,
): AxiosPromise<APIResponseList<ReturnFactoryAPIResponse.RepairListItem>> => {
  return request({
    url: '/repair/getList',
    method: 'post',
    data,
  })
}

/**
 * 获取返厂详情
 * @param {String} id - 返厂id
 */
export const getReturnFactoryDetail = (
  id: string,
): AxiosPromise<ReturnFactoryAPIResponse.Detail> => {
  return request({
    url: `/repair/getDetail/${id}`,
    method: 'get',
  })
}

/**
 * 根据返厂id获取返厂详情的自定义字段
 * @param {String} id - 返厂id
 */
export const getReturnFactoryDetailCustomField = (
  id: string,
): AxiosPromise<ReturnFactoryAPIResponse.DetailCustomField> => {
  return request({
    url: `/repair/getRepairField/${id}`,
    method: 'get',
  })
}

/**
 * 获取返厂详情操作日志
 * @param {String} id - 返厂id
 * @param {Object} data - 请求参数
 * @param {Number} data.limit - 一页显示多少条
 * @param {Number} data.page - 当前页码
 */
export const getReturnFactoryDetailOperateLog = (
  id: string,
  data: { limit: number; page: number },
): AxiosPromise<ReturnFactoryAPIResponse.DetailOperateLog> => {
  return request({
    url: `/repair/getRepairLogList/${id}`,
    method: 'post',
    data,
  })
}

/**
 * 获取返厂详情产品清单列表
 * @param {String} id - 返厂id
 * @param {Object} data - 请求参数
 * @param {Number} data.limit - 一页显示多少条
 * @param {Number} data.page - 当前页码
 */
export const getReturnFactoryDetailGoodList = (
  id: string,
  data: { limit: number; page: number },
): AxiosPromise<ReturnFactoryAPIResponse.DetailGoodList> => {
  return request({
    url: `/repair/getRepairGoodsDetail/${id}`,
    method: 'post',
    data,
  })
}

/**
 * 获取修改前的返厂的信息
 * @param {String} id - 返厂id
 */
export const getInfoBeforeUpdateReturnFactory = (id: string) => {
  return request({
    url: `/repair/getBoforeUpdateRepairInfo/${id}`,
    method: 'get',
  })
}

/**
 * 根据返厂ID获取返厂模块审核设置
 * @param {String} id - 返厂id
 */
export const getReturnFactoryModuleCheckSetById = (
  id: string,
): AxiosPromise<APIResponse<{ repairCheckType: 1 | 2 }>> => {
  return request({
    url: `/repair/getRepairCheckSet/${id}`,
    method: 'get',
  })
}

/**
 * 获取待审核的返厂产品
 * @param {String} id - 返厂id
 */
export const getReturnFactoryWaitCheckGoods = (
  id: string,
): AxiosPromise<ReturnFactoryAPIResponse.WaitCheckGoodList> => {
  return request({
    url: `/repair/getWaitCheckRepairGoods/${id}`,
    method: 'get',
  })
}

/**
 * 返厂审核
 * @param {String} id - 返厂id
 * @param {ReturnFactoryAPIRequest.ReturnFactoryCheckForm} data - 请求参数
 */
export const returnFactoryCheck = (
  id: string,
  data: ReturnFactoryAPIRequest.ReturnFactoryCheckForm,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/repair/checkRepair/${id}`,
    method: 'post',
    data,
  })
}

/**
 * 返厂物流信息保存
 * @param {String} id - 返厂id
 * @param {ReturnFactoryAPIRequest.ReturnFactoryLogisticsInfoSave} data - 请求参数
 */
export const saveReturnFactoryLogisticsInfo = (
  id: string,
  data: ReturnFactoryAPIRequest.ReturnFactoryLogisticsInfoSave,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/repair/saveRepairLogistics/${id}`,
    method: 'post',
    data,
  })
}

/**
 * 获取物流选项
 * @param {Object} data - 请求参数
 * @param {Number} data.limit - 一页显示多少条
 * @param {Number} data.page - 当前页码
 * @param {String} data.name - 搜索关键词
 */
export const getLogisticsOptions = (data: {
  limit: number
  page: number
  name: string
}): AxiosPromise<APIResponseList<{ code: string; name: string }>> => {
  return request({
    url: '/system/logistics/getLogisticsSelectList',
    method: 'post',
    data,
  })
}

/**
 * 根据返厂产品清单ID获取返厂产品信息
 * @param {String} id - 返厂产品清单id
 */
export const getReturnFactoryGoodDetailById = (
  id: string,
): AxiosPromise<ReturnFactoryAPIResponse.GoodDetail> => {
  return request({
    url: `/repair/getUpdateBeforeRepairGoodsInfo/${id}`,
    method: 'get',
  })
}

/**
 * 获取返厂签收校对设置
 * @param {String} id - 返厂id
 */
export const getReturnFactoryReceiptProofreadingSet = (
  id: string,
): AxiosPromise<APIResponse<{ enabledSnCodeCheck: boolean }>> => {
  return request({
    url: `/repair/getSignForCheckSet/${id}`,
    method: 'get',
  })
}

/**
 * 保存返厂签收产品
 * @param {String} id - 返厂id
 * @param {Array} data - 请求参数
 */
export const returnFactoryReceiptGoodsSave = (
  id: string,
  data: Array<ReturnFactoryAPIRequest.ReturnFactoryReceiptGoodSave>,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/repair/saveSignForRepairGoods/${id}`,
    method: 'post',
    data,
  })
}

/**
 * 更新返厂的产品信息
 * @param {String} id - 返厂id
 * @param {Object} data - 请求参数
 * @param {Array<string>} data.images - 返厂图片
 * @param {String} data.repairDescr - 返厂产品问题
 */
export const updateReturnFactoryGoodInfo = (
  id: string,
  data: { images: Array<string>; repairDescr: string },
): AxiosPromise<APIResponse> => {
  return request({
    url: `/repair/saveUpdateRepairGoodsInfo/${id}`,
    method: 'post',
    data,
  })
}

/**
 * 批量允许\禁止选择网点
 * @param {Array<string>} ids - 返厂模块id集合
 * @param {Boolean} enableNetwork - 是否允许选择网点
 */
export const updateNetworkSelectStatus = (
  ids: Array<string>,
  enableNetwork: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/updateEnableNetwork',
    method: 'post',
    params: {
      enableNetwork,
    },
    data: ids,
  })
}

/**
 * 根据返厂模块id集合，更新物流填写状态
 * @param {Array<string>} ids - 返厂模块id集合
 * @param {Boolean} enableWriteLogistics - 是否开启填写物流
 */
export const updateReturnFactoryModuleLogisticsWriteStatusByIds = (
  ids: Array<string>,
  enableWriteLogistics: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/updateEnableEnableWriteLogistics',
    method: 'post',
    params: {
      enableWriteLogistics,
    },
    data: ids,
  })
}

/**
 * 根据返厂模块id集合更新签收开启/关闭状态
 * @param {Array<string>} ids - 返厂模块id集合
 * @param {Boolean} enableRepairSignFor - 是否开启返厂签收：false-关闭，true-开启
 */
export const updateReturnFactoryModuleReceiptByIds = (
  ids: Array<string>,
  enableRepairSignFor: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/updateEnableEnableRepairSignFor',
    method: 'post',
    params: {
      enableRepairSignFor,
    },
    data: ids,
  })
}

/**
 * 创建检测单
 * @param {ReturnFactoryAPIRequest.DetectCreate} data - 请求参数
 */
export const detectCreate = (
  data: ReturnFactoryAPIRequest.DetectCreate,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/check/save',
    method: 'post',
    data,
  })
}

/**
 * 获取检测列表
 * @param {Object} data - 请求参数
 * @param {Number} data.limit - 一页显示多少条
 * @param {Number} data.page - 当前页码
 * @param {String} data.repairCheckNo - 检测单号
 * @param {String} data.userSearch - 公司搜索关键词：公司姓名/公司手机号
 */
export const getDetectList = (data: {
  limit: number
  page: number
  repairCheckNo: string
  userSearch: string
}): AxiosPromise<ReturnFactoryAPIResponse.DetectList> => {
  return request({
    url: '/repair/check/getList',
    method: 'post',
    data,
  })
}

/**
 * 获取检测单详情
 * @param {String} id - 检测单id
 */
export const getDetectDetail = (
  id: string,
): AxiosPromise<ReturnFactoryAPIResponse.DetectDetail> => {
  return request({
    url: `/repair/check/getDetail/${id}`,
    method: 'get',
  })
}

/**
 * 获取检测单自定义字段
 * @param {String} id - 检测单id
 */
export const getDetectDetailCustomField = (id: string) => {
  return request({
    url: `/repair/check/getRepairCheckField/${id}`,
    method: 'get',
  })
}

/**
 * 获取检测清单
 * @param {String} id - 检测单id
 */
export const getDetectGoodList = (
  id: string,
): AxiosPromise<ReturnFactoryAPIResponse.DetectGood> => {
  return request({
    url: `/repair/check/getRepairCheckGoods/${id}`,
    method: 'get',
  })
}

/**
 * 保存检测结果
 * @param {Array<ReturnFactoryAPIRequest.DetectResultSave>} data - 请求参数
 * @param {String} id - 检测单id
 */
export const detectResultSave = (
  data: Array<ReturnFactoryAPIRequest.DetectResultSave>,
  id: string,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/repair/check/saveRepairCheckResult/${id}`,
    method: 'post',
    data,
  })
}

/**
 * 获取公司收货地址
 * @param {String} id - 返厂id
 */
export const getCustomerReceiptAddress = (
  id: string,
): AxiosPromise<ReturnFactoryAPIResponse.CustomerReceiptAddress> => {
  return request({
    url: `/repair/getCustomerReceiveAddr/${id}`,
    method: 'get',
  })
}

/**
 * 确认公司签收
 * @param {String} id - 返厂id
 * @param {Array<string>} returnFactoryGoodIds  - 返厂产品id
 */
export const customerReceiptConfirm = (
  id: string,
  returnFactoryGoodIds: Array<string>,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/repair/saveRepairSureSign/${id}`,
    method: 'post',
    data: returnFactoryGoodIds,
  })
}

/**
 * 填写退回物流
 * @param {String} id - 返厂id
 * @param {ReturnFactoryAPIRequest.ReturnLogisticsFillParam} data - 请求参数
 */
export const returnLogisticsFill = (
  id: string,
  data: ReturnFactoryAPIRequest.ReturnLogisticsFillParam,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/repair/saveCustomerReceiveAddr/${id}`,
    method: 'post',
    data,
  })
}

/**
 * 模块检测字段关联
 * @param {ReturnFactoryAPIRequest.ModuleDetectFieldConnect} data - 请求参数
 */
export const moduleDetectFieldConnect = (
  data: ReturnFactoryAPIRequest.ModuleDetectFieldConnect,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/check/field/save',
    method: 'post',
    data,
  })
}

/**
 * 获取检测自定义字段下拉选项
 * @param {Object} data - 请求参数
 * @param {String} data.name - 搜索关键字
 * @param {Number} data.page - 当前页码
 * @param {Number} data.limit - 一页显示多少条
 */
export const getDetectCustomFieldOptions = (data: {
  limit: number
  name: string
  page: number
}): AxiosPromise<ReturnFactoryAPIResponse.DetectFieldOptions> => {
  return request({
    url: '/repair/select/getRepairCheckFieldSelect',
    method: 'post',
    data,
  })
}

/**
 * 获取返厂模块检测字段列表
 * @param {String} id - 返厂模块id
 * @param {Object} data - 请求参数
 * @param {Number} data.limit - 一页显示多少条
 * @param {Number} data.page - 当前页码
 */
export const getModuleDetectFieldList = (
  id: string,
  data: { limit: number; page: number },
): AxiosPromise<ReturnFactoryAPIResponse.DetectCustomFieldList> => {
  return request({
    url: `/repair/module/check/field/getList/${id}`,
    method: 'post',
    data,
  })
}

/**
 * 获取模块检测字段关联详情
 * @param {String} id - 关联id
 */
export const getModuleDetectFieldConnectDetail = (
  id: string,
): AxiosPromise<ReturnFactoryAPIResponse.ModuleDetectFieldConnectDetail> => {
  return request({
    url: `/repair/module/check/field/getDetail/${id}`,
    method: 'get',
  })
}

/**
 * 批量删除模块关联字段
 * @param {Array<string>} ids 模块关联检测字段ID集合
 */
export const moduleDetectFieldConnectDel = (ids: Array<string>): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/check/field/delete',
    method: 'post',
    data: ids,
  })
}

/**
 * 模块关联检测字段修改为必填/不必填
 * @param {Array<string>} ids - 字段id集合
 * @param {Boolean} required - 是否必填
 */
export const moduleConnectDetectFieldRequiredUpdateByIds = (
  ids: Array<string>,
  required: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/check/field/updateRequired',
    method: 'post',
    params: {
      required,
    },
    data: ids,
  })
}

/**
 * 模块关联检测字段修改为移动端显示/隐藏
 * @param {Array<string>} ids - 字段id集合
 * @param {Boolean} mobileShow - 是否必填：false-隐藏，true-显示
 */
export const moduleConnectDetectFieldMobileShowUpdateByIds = (
  ids: Array<string>,
  mobileShow: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/module/check/field/updateMobileShow',
    method: 'post',
    params: {
      mobileShow,
    },
    data: ids,
  })
}

/**
 * 新增或修改返厂地址库
 * @param {ReturnFactoryAPIRequest.AddressSave} data - 请求参数
 */
export const addressSave = (
  data: ReturnFactoryAPIRequest.AddressSave,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/addr/store/save',
    method: 'post',
    data,
  })
}

/**
 * 获取地址库列表
 * @param data - 请求参数
 */
export const getAddressList = (data: {
  keyword: string
  limit: number
  page: number
}): AxiosPromise<ReturnFactoryAPIResponse.AddressList> => {
  return request({
    url: '/repair/addr/store/getList',
    method: 'post',
    data,
  })
}

/**
 * 批量删除地址库
 * @param ids - 地址id集合
 */
export const addressDelByIds = (ids: Array<string>): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/addr/store/delete',
    method: 'post',
    data: ids,
  })
}

/**
 * 批量启用或禁用地址库
 * @param ids - 地址id集合
 */
export const addressUpdateStateByIds = (
  ids: Array<string>,
  status: boolean,
): AxiosPromise<APIResponse> => {
  return request({
    url: '/repair/addr/store/disalbe',
    method: 'post',
    data: ids,
    params: {
      status,
    },
  })
}

/**
 * 获取地址详情
 * @param id - 地址id
 */
export const getAddressDetail = (
  id: string,
): AxiosPromise<ReturnFactoryAPIResponse.AddressDetail> => {
  return request({
    url: `/repair/addr/store/getDetail/${id}`,
    method: 'get',
  })
}

/**
 * 获取返厂收货地址
 * @param id - 返厂ID
 */
export const getReceiptAddress = (
  id: string,
): AxiosPromise<ReturnFactoryAPIResponse.ReceiptAddress> => {
  return request({
    url: `/repair/getFactoryReceiveAddr/${id}`,
    method: 'get',
  })
}

/**
 * 提交之前进行检测
 * @param id - 返厂检测单ID
 */
export const checkBeforeDetectResultSubmit = (
  id: string,
): AxiosPromise<NewAPIResponse<ReturnFactoryAPIResponse.CheckResultBeforeDetectResultSubmit>> => {
  return request({
    url: `/repair/check/verifyCheckStatusBeforeSubmit/${id}`,
    method: 'get',
  })
}

/**
 * 提交返厂检测单
 * @param data - 请求参数
 * @param id - 返厂检测单ID
 */
export const submitDetectResult = (
  data: Array<ReturnFactoryAPIRequest.DetectResultSubmit>,
  id: string,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/repair/check/submit/${id}`,
    method: 'post',
    data,
  })
}

/**
 * 实收未过账过账接口
 * @param data - 请求参数
 * @param repairId - 返厂单id
 */
export const actualCollectPosting = (
  data: Array<{ goodsNumberInFace: number; goodsNumberInPlan: number; repairGoodsId: string }>,
  repairId: string,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/repair/postingAtReturn/${repairId}`,
    method: 'post',
    data,
  })
}

/**
 * 实发未过账过账接口
 * @param data - 请求参数
 * @param repairId - 返厂单id
 */
export const actualSendPosting = (
  data: Array<{ goodsNumberInFace: number; goodsNumberInPlan: number; repairGoodsId: string }>,
  repairId: string,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/repair/postingAtSend/${repairId}`,
    method: 'post',
    data,
  })
}

/**
 * 返厂单反过账接口
 * @param repairId - 返厂单id
 * @param deliveryNo - 实收过账单号
 * @param status - 返厂单状态
 */
export const repairReversePosting = (
  repairId: string,
  deliveryNo: string,
  status: number,
): AxiosPromise<APIResponse> => {
  return request({
    url: `/repair/antiPostingInRepairBothReturnAndSend/${repairId}/${deliveryNo}/${status}`,
    method: 'get',
  })
}

/**
 * 返厂页面下面获取发货列表接口
 * @param repairId - 返厂单id
 */
export const getRepairSendGoodList = (
  repairId: string,
): AxiosPromise<NewAPIResponse<{ data: Array<ReturnFactoryAPIResponse.SendedGoodListItem> }>> => {
  return request({
    url: `/repair/getSendList/${repairId}`,
    method: 'get',
  })
}
